import os.path

from PIL import Image
from django.db.models import Q

from Wallpaper.models import Wallpaper


def set_img_info():
    root = r"E:\Android\Service\MyStation\static\media\staticwallpaper\vertical"
    path_list = os.listdir(path=root)
    for path in path_list:
        path = os.path.join(root, path)
        s = Image.open(path).size
        memory_size = os.path.getsize(path)
        size = f"{s[0]}x{s[1]}"
        try:
            wallpaper = Wallpaper.objects.get(Q(url__contains=path.rsplit("\\")[-1]))
            wallpaper.file_size = memory_size
            wallpaper.resolution = size
            wallpaper.save()
        except:
            print("Error")

# if __name__ == '__main__':
